package com.cskaoyan.shopping.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.dto.ProductDetailDto;
import com.cskaoyan.shopping.dto.AllProductResponse;
import com.cskaoyan.shopping.dto.ItemCatDto;
import com.cskaoyan.shopping.dto.PanelContentDto;
import com.cskaoyan.shopping.dto.PanelDto;
import com.cskaoyan.shopping.form.PageRequest;
import com.cskaoyan.shopping.service.IHomeService;
import com.cskaoyan.shopping.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Set;

/**
 * @Description:查看商品详情、分页查询商品列表、查询推荐商品接口
 * @Author: Pinocao
 * @CreateTime: 2022-12-03  09:21
 * @Version: 1.0
 */
@RestController
@RequestMapping("shopping")
public class ProductController {
    @Autowired
    IProductService iProductService;

    // 查看商品详情
    @GetMapping("product/{id}")
    public ResponseData getProductDetail(@PathVariable("id") @NotNull(message = "id不能为null") Long id){
        ProductDetailDto productDetail = iProductService.getProductDetail(id);
        return new ResponseUtil<ProductDetailDto>().setData(productDetail, "success");
    }

    // 分页查询商品列表
    @GetMapping("goods")
    public ResponseData getAllProduct(PageRequest pageRequest){
        AllProductResponse allProduct = iProductService.getAllProduct(pageRequest);
        return new ResponseUtil<AllProductResponse>().setData(allProduct, "success");
    }

    // 查询推荐商品接口
    @GetMapping("recommend")
    public ResponseData getRecommendGoods(){
        Set<PanelDto> recommendGoods = iProductService.getRecommendGoods();
        return new ResponseUtil<Set>().setData(recommendGoods, "success");
    }




    @Autowired
    IHomeService iHomeService;
    // 主页显示接口
    @GetMapping("/homepage")
    public ResponseData showHomePage(){
        List<PanelDto> panelDtos = iHomeService.homepage();
        return new ResponseUtil().setData(panelDtos,"success");
    }

    // 导航栏显示
    @GetMapping("/navigation")
    public ResponseData showNavigation(){

        List<PanelContentDto> panelContentDtos = iHomeService.navigation();
        return new ResponseUtil().setData(panelContentDtos,"success");
    }

    // 列举所有商品种类
    @GetMapping("/categories")
    public ResponseData showCategories(){
        List<ItemCatDto> itemCatDtos = iHomeService.categories();
        return new ResponseUtil().setData(itemCatDtos,"success");
    }
}